New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add top-level error labels to write concern error #766
Conversation
This will allow the driver to properly retry writes that the server has labeled as a RetryableWriteError. JAVA-4244
@@ -264,7 +265,9 @@ public static MongoException createSpecialException(final BsonDocument response, | |||
} else if (isNotPrimaryError(errorCode, errorMessage)) { | |||
return new MongoNotPrimaryException(response, serverAddress); | |||
} else if (response.containsKey("writeConcernError")) { | |||
return createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg"); | |||
return createSpecialException(response.getDocument("writeConcernError").clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty hacky to clone the writeConcernError document so we can append errorLabels to it, but it's the most localized fix. Happy to entertain other ideas though
import java.net.URISyntaxException; | ||
import java.util.Collection; | ||
|
||
public class UnifiedRetryableWritesTest extends UnifiedReactiveStreamsTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the first unified retryable writes tests so need new runners for them.
@@ -0,0 +1,205 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these two new unified tests for this, in scope of already existing DRIVERS-1385 ticket.
Sharded tests are failing... Converting to draft while investigation is in progress. |
@@ -264,7 +265,16 @@ public static MongoException createSpecialException(final BsonDocument response, | |||
} else if (isNotPrimaryError(errorCode, errorMessage)) { | |||
return new MongoNotPrimaryException(response, serverAddress); | |||
} else if (response.containsKey("writeConcernError")) { | |||
return createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg"); | |||
BsonDocument writeConcernError = response.getDocument("writeConcernError"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is more complex than it needs to be:
MongoException error = createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg");
for (BsonValue errorLabel : response.getArray("errorLabels", new BsonArray())) {
error.addLabel(errorLabel.asString().getValue());
}
return error;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's so much better. Thanks. Added a couple of checks to a conditional protecting the loop. One is necessary for correctness, the other just to document intent.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This will allow the driver to properly retry writes that the server has labeled as a RetryableWriteError. JAVA-4244
This will allow the driver to properly retry writes that the server has labeled as a RetryableWriteError. JAVA-4244
This will allow the driver to properly retry writes that the server has labeled as a RetryableWriteError. JAVA-4244
This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.
JAVA-4244